import 'package:flutter/material.dart';
import 'package:library_base/ext/bool_ext.dart';
import 'package:library_base/ext/theme_data_ext.dart';
import 'package:library_base/global/multi_language.dart';
import 'package:get/get.dart';
import 'package:library_base/res/styles.dart';
import 'package:library_base/utils/sp_util.dart';
import 'package:library_base/utils/theme_util.dart';
import 'package:library_base/ext/list_ext.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

Widget buildHead() {
  List<String> headTitles = [
    MultiLanguage.serialNumber.tr,
    MultiLanguage.prefix.tr,
    MultiLanguage.barcode.tr,
    MultiLanguage.weightCatties.tr+SPUtil.isJin.unitStrZhWithBracket(),
    MultiLanguage.serviceCharge.tr
  ];
  List<int> flexes = [2,2,3, 3, 3];

  List<Widget> widgets = [];

  flexes.forEachIndexed((index, action) {
    widgets.add(Expanded(
      flex: flexes[index],
      child: Container(
        alignment: Alignment.center,
        child: Text(
          headTitles[index],
          style: normalTextColor26,
          textAlign: TextAlign.center,
        ),
      ),
    ));
  });

  return Container(
    color: ThemeUtil.getTheme().secondaryBgColor(),
    padding: EdgeInsets.symmetric(vertical: 24.w),
    child: Row(
      children: widgets,
    ),
  );
}

Widget buildInput({
  TextEditingController? controller,
  TextInputType? keyboardType = TextInputType.number,
  ValueChanged<String>? onChanged,
  BoxDecoration? boxDecoration,
  EdgeInsets? margin,
}) {
  return Container(
      margin: margin??EdgeInsets.symmetric(horizontal: 8.w),
      padding: EdgeInsets.symmetric(horizontal: 15.w, vertical: 15.w),
      decoration: boxDecoration??BoxDecoration(
          color: ThemeUtil.getTheme().colorScheme.secondary,
          borderRadius: const BorderRadius.all(Radius.circular(30.0)),
          border: Border.all(color: ThemeUtil.getTheme().sixthTextColor(), width: 0.7)),
      alignment: Alignment.center,
      child: TextField(
        style: TextStyles.textNormal28,
        keyboardType: keyboardType,
        onChanged: onChanged,
        autofocus: false,
        controller: controller,
        textAlign: TextAlign.center,
        decoration: InputDecoration(
          isDense: true,
          focusedBorder:
              const OutlineInputBorder(borderSide: BorderSide(width: 0, color: Colors.transparent)),
          disabledBorder:
              const OutlineInputBorder(borderSide: BorderSide(width: 0, color: Colors.transparent)),
          enabledBorder:
              const OutlineInputBorder(borderSide: BorderSide(width: 0, color: Colors.transparent)),
          contentPadding: const EdgeInsets.symmetric(vertical: 0),
          border: InputBorder.none,
          labelStyle: TextStyles.textNormal28,
        ),
      ));
}
